<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Lib\RsaSecurity;
class ServerController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }
    public function serverlist()
    {
      	
	$serverlist = DB::select("SELECT * FROM b_server where isdelete = '0'"); 
	
	 
	foreach($serverlist as $server)
	{
		$server->passwd=RsaSecurity::privEncrypt($server->passwd);
	}
	if(empty($serverlist)){
	   $result['status']='0';
	   $result['message']='服务器信息不存在';
	   $result['adInterstitial']='ca-app-pub-8699135107163298/8251586169';
           $result['banner']='ca-app-pub-8699135107163298/6774852966';
           $result['interval']=1800;
	   $result['version']='1.5.3';
	   $result['showOtherPayment']=1;
	   $result['slogan']='';
	   return response()->json($result);	
	}else{
	   $result['status']='1';
	   $result['message']='服务器信息返回成功';
	   $result['adInterstitial']='ca-app-pub-8699135107163298/8251586169';
           $result['banner']='ca-app-pub-8699135107163298/6774852966';
           $result['interval']=1800;
           $result['version']='1.5.3';
           $result['showOtherPayment']=1;
	   $result['result']=$serverlist;
           $result['slogan']='';
	   return response()->json($result);
	}
	//return response()->json($serverlist);
	
	//return 'Hello';
        //return view('user.index', ['users' => $users]);
  
    }

    public function storeFeedBack(Request $request)
    {
        if($request->has('feedback') && $request->has('version')){
	    $feedback = $request->input('feedback');
	    $version = $request->input('version');
	   // DB::insert('insert into b_feedback (feedback,version) values (?,?)',[$feedback,$version]);
	    $id = DB::table('b_feedback')->insertGetId(
		['feedback'=>$feedback,'version'=>$version]
	    );
            if(!empty($id)){
		$result['status']='1';
		$result['message']='反馈信息提交成功';
		return response()->json($result);	
	    }else{
		$result['status']='0';
		$result['message']='反馈信息插入失败';
		return response()->json($result);
	    }
	}else{
		$result['status']='0';
		$result['message']='缺少填充信息';
		return response()->json($result);
	}
	

    }
    public function saveDonation(Request $request)
    {
    	if($request->has('name') && $request->has('money') && $request->has('type'))
	{
	    $name = $request->input('name');
	    $money = $request->input('money');
            $type = $request->input('type');
            $id = DB::table('b_donation')->insertGetId(
              ['name'=>$name,'money'=>$money,'type'=>$type]
	    );
	    if(!empty($id)){
               $result['status']='1';
	       $result['message']='捐赠信息提交成功';
	       return response()->json($result);
	    }else{
               $result['status']='0';
               $result['message']='捐赠信息插入失败';
	       return response()->json($result);
	    }
	}else{
	    $result['status']='0';
	    $result['message']='缺少填充信息';
	    return response()->json($result);
	}
    }
    //
    public function donation()
    {
	$donationlist = DB::select("select name,money from b_donation");
	if(!empty($donationlist)){
	    $result['status']='1';
	    $result['message']='捐赠列表返回成功';
	    $result['result']=$donationlist;
	    return response()->json($result);
	}else{
            $result['message']='捐赠列表获取失败';
	    $result['status']='0';
        }
	return response()->json($donationlist);
    }
}
